package com.ts.api.module.api.convert.market.adapter;

import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarket;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarketConvertType;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.market.entity.ChannelMarketParameter;
import com.ts.api.module.api.convert.market.handler.ChannelMarketConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;

import java.util.Map;

/**
 *  H5上游渠道产品-手机号模式联登-匹配相同模式贷超
 *
 *  @author Pan
 */
@ApiChannelMarket(uniqueCode = "channelMarketFederateToConsumerMarketAdapter", type = ApiChannelMarketConvertType.FEDERATE_TO_CONSUMER_MARKET)
public class ChannelMarketFederateToConsumerMarketAdapter implements ChannelMarketConvertHandler {

    @Override
    public ApiUserRequest parse(RequestVO requestVO) {
        return decrypt(requestVO);
    }

    @Override
    public Map<String, Object> response(ChannelMarketParameter channelMarketParameter, ApiBizStatus apiBizStatus) {
        if (apiBizStatus.hasBizSuc()) {
            return MapUtils.newHashMap(newHashMap -> {
                newHashMap.put("code", 1000);
                newHashMap.put("msg", "成功");
                newHashMap.put("url", channelMarketParameter.getUrl());
            });
        }
        return MapUtils.newHashMap(newHashMap -> {
            newHashMap.put("code", 0);
            newHashMap.put("msg", apiBizStatus.getBizMsg());
        });
    }
}
